package groupb6.shopsystem.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import groupb6.shopsystem.pojo.entity.Order;
import groupb6.shopsystem.pojo.entity.Product;
import groupb6.shopsystem.pojo.entity.ShoppingBag;
import groupb6.shopsystem.pojo.form.AdmitOrderForm;
import groupb6.shopsystem.pojo.form.CustomerCartEditForm;
import groupb6.shopsystem.pojo.form.OrderIdForm;
import groupb6.shopsystem.pojo.res.ShoppingBagRes;
import groupb6.shopsystem.pojo.template.PageInfo;
import groupb6.shopsystem.service.CustomerCartService;
import groupb6.shopsystem.util.response.UniversalResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.ArrayList;

@Api(tags = "12:购物车详情页")
@ApiSupport(author = "zyliang")
@RestController
@RequestMapping("/customer") // check
public class CustomerCartController {
    @Autowired
    private CustomerCartService customerCartService;

    @ApiOperation("查看购物车")
    @GetMapping("/getcart") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse<List<ShoppingBagRes>> shoppingbag() {
        return customerCartService.getShoppingBag();
    }

    @ApiOperation("提交订单")
    @PostMapping("/admitOrder") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse admitOrder(@RequestBody List<AdmitOrderForm> admitOrderForm) {
        return customerCartService.admitOrder(admitOrderForm);
    }
    @ApiOperation("取消订单")
    @PostMapping("/cancelOrder") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse cancelOrder(@RequestBody OrderIdForm orderIdForm) {
        customerCartService.cancelOrder(orderIdForm.getOrderId());
        return new UniversalResponse().ok();
    }

    @ApiOperation("支付订单")
    @PostMapping("/payOrder") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse<?> payOrder(@RequestBody List<OrderIdForm> orderIdListForm) {
        return customerCartService.payOrder(orderIdListForm);
    }

    @ApiOperation("清空购物车")
    @PostMapping("/clear") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse<?> clear() {
       customerCartService.clearCart();
       return  new UniversalResponse<>().ok();
    }
    @ApiOperation("调整购物车物品数量（0为删除）")
    @PostMapping("/editNumber") // check
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "成功")})
    @ResponseBody
    public UniversalResponse<?> editNumber(@RequestBody CustomerCartEditForm customerCartEditForm) {
        customerCartService.editCart(customerCartEditForm);
        return new UniversalResponse<>().ok();
    }

}
